package cn.bdqn.text;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/html/userServlet")
public class UserServlet extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
        String name = request.getParameter("name");
        boolean used = false;    // 名字是否被使用  默认值是false
        if("ajax".equals(name)){
            used = true;
        }else {
            used = false;
        }
        response.setContentType("text/html;charset= UTF-8");  // 设置内容为文本类型  字符编码
        PrintWriter out = response.getWriter();
        out.print(used);  // 输出响应
        out.flush();   // 刷新
        out.close();   // 关闭
    }
    public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");   // 设置字符编码
        this.doGet(request,response);            // 调用doGet 方法
    }
}
